package org.example.everyday;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * Description:TODO 详细描述
 * <p>
 * Copyright: 天津联想协同科技有限公司
 * <p>
 *
 * @author anlu
 * @date 2022/4/18 16:06
 */
public class Lc386 {
    public static void main(String[] args) {
        Lc386 lc386 = new Lc386();
        List<Integer> res = lc386.lexicalOrder(13);
        for (int i = 0; i < res.size(); i++) {
            System.out.println(res.get(i));
        }

    }

    /**
     * 方法描述: 输入：n = 13
     * 输出：[1,10,11,12,13,2,3,4,5,6,7,8,9]
     *
     * @param n .
     * @return java.util.List<java.lang.Integer>
     * @author 安路路
     * @date 2022/4/18  16:38
     */
    public List<Integer> lexicalOrder(int n) {
       List<Integer> ret = new ArrayList<>();
       int num = 1;
        for (int i = 0; i < n; i++) {
            ret.add(num);
            if(num * 10 <= n){
                num *= 10;
            }else{
                while (num % 10 == 9 || num + 1 > n){
                    num /= 10;
                }
                num++;
            }
        }
        return ret;
    }

}
